/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  @endpointMap = {
    ap-northeast-2-pop = 'actiontrail.ap-northeast-1.aliyuncs.com',
    cn-beijing-finance-1 = 'actiontrail.aliyuncs.com',
    cn-beijing-finance-pop = 'actiontrail.aliyuncs.com',
    cn-beijing-gov-1 = 'actiontrail.aliyuncs.com',
    cn-beijing-nu16-b01 = 'actiontrail.aliyuncs.com',
    cn-edge-1 = 'actiontrail.aliyuncs.com',
    cn-fujian = 'actiontrail.aliyuncs.com',
    cn-haidian-cm12-c01 = 'actiontrail.aliyuncs.com',
    cn-hangzhou-bj-b01 = 'actiontrail.aliyuncs.com',
    cn-hangzhou-finance = 'actiontrail.aliyuncs.com',
    cn-hangzhou-internal-prod-1 = 'actiontrail.aliyuncs.com',
    cn-hangzhou-internal-test-1 = 'actiontrail.aliyuncs.com',
    cn-hangzhou-internal-test-2 = 'actiontrail.aliyuncs.com',
    cn-hangzhou-internal-test-3 = 'actiontrail.aliyuncs.com',
    cn-hangzhou-test-306 = 'actiontrail.aliyuncs.com',
    cn-hongkong-finance-pop = 'actiontrail.aliyuncs.com',
    cn-qingdao-nebula = 'actiontrail.aliyuncs.com',
    cn-shanghai-et15-b01 = 'actiontrail.aliyuncs.com',
    cn-shanghai-et2-b01 = 'actiontrail.aliyuncs.com',
    cn-shanghai-inner = 'actiontrail.aliyuncs.com',
    cn-shanghai-internal-test-1 = 'actiontrail.aliyuncs.com',
    cn-shenzhen-finance-1 = 'actiontrail.aliyuncs.com',
    cn-shenzhen-inner = 'actiontrail.aliyuncs.com',
    cn-shenzhen-st4-d01 = 'actiontrail.aliyuncs.com',
    cn-shenzhen-su18-b01 = 'actiontrail.aliyuncs.com',
    cn-wuhan = 'actiontrail.aliyuncs.com',
    cn-yushanfang = 'actiontrail.aliyuncs.com',
    cn-zhangbei-na61-b01 = 'actiontrail.aliyuncs.com',
    cn-zhangjiakou-na62-a01 = 'actiontrail.aliyuncs.com',
    cn-zhengzhou-nebula-1 = 'actiontrail.aliyuncs.com',
    eu-west-1-oxs = 'actiontrail.ap-northeast-1.aliyuncs.com',
    rus-west-1-pop = 'actiontrail.ap-northeast-1.aliyuncs.com',
  };

  checkConfig(config);
  @endpoint = getEndpoint('actiontrail', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CreateTrailRequest {
  eventRW?: string(name='EventRW'),
  isOrganizationTrail?: boolean(name='IsOrganizationTrail'),
  mnsTopicArn?: string(name='MnsTopicArn'),
  name?: string(name='Name'),
  ossBucketName?: string(name='OssBucketName'),
  ossKeyPrefix?: string(name='OssKeyPrefix'),
  roleName?: string(name='RoleName'),
  slsProjectArn?: string(name='SlsProjectArn'),
  slsWriteRoleArn?: string(name='SlsWriteRoleArn'),
  trailRegion?: string(name='TrailRegion'),
}

model CreateTrailResponseBody = {
  eventRW?: string(name='EventRW'),
  homeRegion?: string(name='HomeRegion'),
  mnsTopicArn?: string(name='MnsTopicArn'),
  name?: string(name='Name'),
  ossBucketName?: string(name='OssBucketName'),
  ossKeyPrefix?: string(name='OssKeyPrefix'),
  requestId?: string(name='RequestId'),
  roleName?: string(name='RoleName'),
  slsProjectArn?: string(name='SlsProjectArn'),
  slsWriteRoleArn?: string(name='SlsWriteRoleArn'),
  trailRegion?: string(name='TrailRegion'),
}

model CreateTrailResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CreateTrailResponseBody(name='body'),
}

async function createTrailWithOptions(request: CreateTrailRequest, runtime: Util.RuntimeOptions): CreateTrailResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.eventRW)) {
    query['EventRW'] = request.eventRW;
  }
  if (!Util.isUnset(request.isOrganizationTrail)) {
    query['IsOrganizationTrail'] = request.isOrganizationTrail;
  }
  if (!Util.isUnset(request.mnsTopicArn)) {
    query['MnsTopicArn'] = request.mnsTopicArn;
  }
  if (!Util.isUnset(request.name)) {
    query['Name'] = request.name;
  }
  if (!Util.isUnset(request.ossBucketName)) {
    query['OssBucketName'] = request.ossBucketName;
  }
  if (!Util.isUnset(request.ossKeyPrefix)) {
    query['OssKeyPrefix'] = request.ossKeyPrefix;
  }
  if (!Util.isUnset(request.roleName)) {
    query['RoleName'] = request.roleName;
  }
  if (!Util.isUnset(request.slsProjectArn)) {
    query['SlsProjectArn'] = request.slsProjectArn;
  }
  if (!Util.isUnset(request.slsWriteRoleArn)) {
    query['SlsWriteRoleArn'] = request.slsWriteRoleArn;
  }
  if (!Util.isUnset(request.trailRegion)) {
    query['TrailRegion'] = request.trailRegion;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CreateTrail',
    version = '2017-12-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createTrail(request: CreateTrailRequest): CreateTrailResponse {
  var runtime = new Util.RuntimeOptions{};
  return createTrailWithOptions(request, runtime);
}

model DeleteTrailRequest {
  name?: string(name='Name'),
}

model DeleteTrailResponseBody = {
  requestId?: string(name='RequestId'),
}

model DeleteTrailResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: DeleteTrailResponseBody(name='body'),
}

async function deleteTrailWithOptions(request: DeleteTrailRequest, runtime: Util.RuntimeOptions): DeleteTrailResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.name)) {
    query['Name'] = request.name;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'DeleteTrail',
    version = '2017-12-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function deleteTrail(request: DeleteTrailRequest): DeleteTrailResponse {
  var runtime = new Util.RuntimeOptions{};
  return deleteTrailWithOptions(request, runtime);
}

model DescribeRegionsResponseBody = {
  regions?: {
    region?: [ 
      {
        regionId?: string(name='RegionId'),
      }
    ](name='Region'),
  }(name='Regions'),
  requestId?: string(name='RequestId'),
}

model DescribeRegionsResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: DescribeRegionsResponseBody(name='body'),
}

async function describeRegionsWithOptions(runtime: Util.RuntimeOptions): DescribeRegionsResponse {
  var req = new OpenApi.OpenApiRequest{};
  var params = new OpenApi.Params{
    action = 'DescribeRegions',
    version = '2017-12-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function describeRegions(): DescribeRegionsResponse {
  var runtime = new Util.RuntimeOptions{};
  return describeRegionsWithOptions(runtime);
}

model DescribeTrailsRequest {
  includeOrganizationTrail?: boolean(name='IncludeOrganizationTrail'),
  includeShadowTrails?: boolean(name='IncludeShadowTrails'),
  nameList?: string(name='NameList'),
}

model DescribeTrailsResponseBody = {
  requestId?: string(name='RequestId'),
  trailList?: [ 
    {
      createTime?: string(name='CreateTime'),
      eventRW?: string(name='EventRW'),
      homeRegion?: string(name='HomeRegion'),
      isOrganizationTrail?: boolean(name='IsOrganizationTrail'),
      mnsTopicArn?: string(name='MnsTopicArn'),
      name?: string(name='Name'),
      ossBucketName?: string(name='OssBucketName'),
      ossKeyPrefix?: string(name='OssKeyPrefix'),
      roleName?: string(name='RoleName'),
      slsProjectArn?: string(name='SlsProjectArn'),
      slsWriteRoleArn?: string(name='SlsWriteRoleArn'),
      startLoggingTime?: string(name='StartLoggingTime'),
      status?: string(name='Status'),
      stopLoggingTime?: string(name='StopLoggingTime'),
      trailRegion?: string(name='TrailRegion'),
      updateTime?: string(name='UpdateTime'),
    }
  ](name='TrailList'),
}

model DescribeTrailsResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: DescribeTrailsResponseBody(name='body'),
}

async function describeTrailsWithOptions(request: DescribeTrailsRequest, runtime: Util.RuntimeOptions): DescribeTrailsResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.includeOrganizationTrail)) {
    query['IncludeOrganizationTrail'] = request.includeOrganizationTrail;
  }
  if (!Util.isUnset(request.includeShadowTrails)) {
    query['IncludeShadowTrails'] = request.includeShadowTrails;
  }
  if (!Util.isUnset(request.nameList)) {
    query['NameList'] = request.nameList;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'DescribeTrails',
    version = '2017-12-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function describeTrails(request: DescribeTrailsRequest): DescribeTrailsResponse {
  var runtime = new Util.RuntimeOptions{};
  return describeTrailsWithOptions(request, runtime);
}

model GetTrailStatusRequest {
  isOrganizationTrail?: boolean(name='IsOrganizationTrail'),
  name?: string(name='Name'),
}

model GetTrailStatusResponseBody = {
  isLogging?: boolean(name='IsLogging'),
  latestDeliveryError?: string(name='LatestDeliveryError'),
  latestDeliveryTime?: string(name='LatestDeliveryTime'),
  requestId?: string(name='RequestId'),
  startLoggingTime?: string(name='StartLoggingTime'),
  stopLoggingTime?: string(name='StopLoggingTime'),
}

model GetTrailStatusResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetTrailStatusResponseBody(name='body'),
}

async function getTrailStatusWithOptions(request: GetTrailStatusRequest, runtime: Util.RuntimeOptions): GetTrailStatusResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.isOrganizationTrail)) {
    query['IsOrganizationTrail'] = request.isOrganizationTrail;
  }
  if (!Util.isUnset(request.name)) {
    query['Name'] = request.name;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetTrailStatus',
    version = '2017-12-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getTrailStatus(request: GetTrailStatusRequest): GetTrailStatusResponse {
  var runtime = new Util.RuntimeOptions{};
  return getTrailStatusWithOptions(request, runtime);
}

model LookupEventsRequest {
  endTime?: string(name='EndTime'),
  event?: string(name='Event'),
  eventAccessKeyId?: string(name='EventAccessKeyId'),
  eventName?: string(name='EventName'),
  eventRW?: string(name='EventRW'),
  eventType?: string(name='EventType'),
  maxResults?: string(name='MaxResults'),
  nextToken?: string(name='NextToken'),
  request?: string(name='Request'),
  resourceName?: string(name='ResourceName'),
  resourceType?: string(name='ResourceType'),
  serviceName?: string(name='ServiceName'),
  startTime?: string(name='StartTime'),
  user?: string(name='User'),
}

model LookupEventsResponseBody = {
  endTime?: string(name='EndTime'),
  events?: [  map[string]any ](name='Events'),
  nextToken?: string(name='NextToken'),
  requestId?: string(name='RequestId'),
  startTime?: string(name='StartTime'),
}

model LookupEventsResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: LookupEventsResponseBody(name='body'),
}

async function lookupEventsWithOptions(request: LookupEventsRequest, runtime: Util.RuntimeOptions): LookupEventsResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.endTime)) {
    query['EndTime'] = request.endTime;
  }
  if (!Util.isUnset(request.event)) {
    query['Event'] = request.event;
  }
  if (!Util.isUnset(request.eventAccessKeyId)) {
    query['EventAccessKeyId'] = request.eventAccessKeyId;
  }
  if (!Util.isUnset(request.eventName)) {
    query['EventName'] = request.eventName;
  }
  if (!Util.isUnset(request.eventRW)) {
    query['EventRW'] = request.eventRW;
  }
  if (!Util.isUnset(request.eventType)) {
    query['EventType'] = request.eventType;
  }
  if (!Util.isUnset(request.maxResults)) {
    query['MaxResults'] = request.maxResults;
  }
  if (!Util.isUnset(request.nextToken)) {
    query['NextToken'] = request.nextToken;
  }
  if (!Util.isUnset(request.request)) {
    query['Request'] = request.request;
  }
  if (!Util.isUnset(request.resourceName)) {
    query['ResourceName'] = request.resourceName;
  }
  if (!Util.isUnset(request.resourceType)) {
    query['ResourceType'] = request.resourceType;
  }
  if (!Util.isUnset(request.serviceName)) {
    query['ServiceName'] = request.serviceName;
  }
  if (!Util.isUnset(request.startTime)) {
    query['StartTime'] = request.startTime;
  }
  if (!Util.isUnset(request.user)) {
    query['User'] = request.user;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'LookupEvents',
    version = '2017-12-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function lookupEvents(request: LookupEventsRequest): LookupEventsResponse {
  var runtime = new Util.RuntimeOptions{};
  return lookupEventsWithOptions(request, runtime);
}

model StartLoggingRequest {
  name?: string(name='Name'),
}

model StartLoggingResponseBody = {
  requestId?: string(name='RequestId'),
}

model StartLoggingResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: StartLoggingResponseBody(name='body'),
}

async function startLoggingWithOptions(request: StartLoggingRequest, runtime: Util.RuntimeOptions): StartLoggingResponse {
  Util.validateModel(request);
  var query = OpenApiUtil.query(Util.toMap(request));
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'StartLogging',
    version = '2017-12-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function startLogging(request: StartLoggingRequest): StartLoggingResponse {
  var runtime = new Util.RuntimeOptions{};
  return startLoggingWithOptions(request, runtime);
}

model StopLoggingRequest {
  name?: string(name='Name'),
}

model StopLoggingResponseBody = {
  requestId?: string(name='RequestId'),
}

model StopLoggingResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: StopLoggingResponseBody(name='body'),
}

async function stopLoggingWithOptions(request: StopLoggingRequest, runtime: Util.RuntimeOptions): StopLoggingResponse {
  Util.validateModel(request);
  var query = OpenApiUtil.query(Util.toMap(request));
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'StopLogging',
    version = '2017-12-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function stopLogging(request: StopLoggingRequest): StopLoggingResponse {
  var runtime = new Util.RuntimeOptions{};
  return stopLoggingWithOptions(request, runtime);
}

model UpdateTrailRequest {
  eventRW?: string(name='EventRW'),
  mnsTopicArn?: string(name='MnsTopicArn'),
  name?: string(name='Name'),
  ossBucketName?: string(name='OssBucketName'),
  ossKeyPrefix?: string(name='OssKeyPrefix'),
  roleName?: string(name='RoleName'),
  slsProjectArn?: string(name='SlsProjectArn'),
  slsWriteRoleArn?: string(name='SlsWriteRoleArn'),
  trailRegion?: string(name='TrailRegion'),
}

model UpdateTrailResponseBody = {
  eventRW?: string(name='EventRW'),
  homeRegion?: string(name='HomeRegion'),
  mnsTopicArn?: string(name='MnsTopicArn'),
  name?: string(name='Name'),
  ossBucketName?: string(name='OssBucketName'),
  ossKeyPrefix?: string(name='OssKeyPrefix'),
  requestId?: string(name='RequestId'),
  roleName?: string(name='RoleName'),
  slsProjectArn?: string(name='SlsProjectArn'),
  slsWriteRoleArn?: string(name='SlsWriteRoleArn'),
  trailRegion?: string(name='TrailRegion'),
}

model UpdateTrailResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: UpdateTrailResponseBody(name='body'),
}

async function updateTrailWithOptions(request: UpdateTrailRequest, runtime: Util.RuntimeOptions): UpdateTrailResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.eventRW)) {
    query['EventRW'] = request.eventRW;
  }
  if (!Util.isUnset(request.mnsTopicArn)) {
    query['MnsTopicArn'] = request.mnsTopicArn;
  }
  if (!Util.isUnset(request.name)) {
    query['Name'] = request.name;
  }
  if (!Util.isUnset(request.ossBucketName)) {
    query['OssBucketName'] = request.ossBucketName;
  }
  if (!Util.isUnset(request.ossKeyPrefix)) {
    query['OssKeyPrefix'] = request.ossKeyPrefix;
  }
  if (!Util.isUnset(request.roleName)) {
    query['RoleName'] = request.roleName;
  }
  if (!Util.isUnset(request.slsProjectArn)) {
    query['SlsProjectArn'] = request.slsProjectArn;
  }
  if (!Util.isUnset(request.slsWriteRoleArn)) {
    query['SlsWriteRoleArn'] = request.slsWriteRoleArn;
  }
  if (!Util.isUnset(request.trailRegion)) {
    query['TrailRegion'] = request.trailRegion;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'UpdateTrail',
    version = '2017-12-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function updateTrail(request: UpdateTrailRequest): UpdateTrailResponse {
  var runtime = new Util.RuntimeOptions{};
  return updateTrailWithOptions(request, runtime);
}

